/*
 * $Id: $
 */
package org.rcgwt.client.ui.grid.internal;

import org.rcgwt.client.ui.grid.internal.model.IElementModel;
import org.rcgwt.client.ui.grid.internal.model.IHeaderModel;
import org.rcgwt.client.ui.grid.internal.model.ITitleCellModel;
import org.rcgwt.client.ui.grid.internal.model.ITitleRowModel;

/**
 * 
 * @author Olivier Oeuillot (latest modification by $Author: $)
 * @version $Revision: $ $Date: $
 */
public class TitleRowModel extends AbstractElementModel implements
		ITitleRowModel {

	private final IHeaderModel header;

	private ITitleCellModel titleCellModels[];

	private boolean hasFocusSupport;

	public TitleRowModel(int modelIndex, IHeaderModel header,
			boolean hasFocusSupport) {
		this.modelIndex = modelIndex;
		this.header = header;
		this.hasFocusSupport = hasFocusSupport;
	}

	@Override
	public Type getType() {
		return Type.TITLE_ROW;
	}

	@Override
	public String toString() {
		return "[TitleRowModel modelIndex=" + modelIndex + " state=0x"
				+ Integer.toHexString(stateMask) + "]";
	}

	@Override
	public IElementModel getParent() {
		return getHeader();
	}

	@Override
	public IHeaderModel getHeader() {
		return header;
	}

	@Override
	protected void constructKey(IKey key) {
		super.constructKey(key);

		key.add("header");
		header.appendKey(key);
	}

	public void setTitleCellModels(ITitleCellModel[] titleCellModels) {
		this.titleCellModels = titleCellModels;
	}

	@Override
	public ITitleCellModel[] listTitleCellModels() {
		return titleCellModels;
	}

	@Override
	public boolean isFocusable() {
		return hasFocusSupport;
	}

}
